package com.kehutong.house.service;


import com.kehutong.house.entity.ShopClassify;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.mvc.webservice.WebService;
import org.coraframework.orm.jdbc.JdbcSession;

@WebService("/basic/shop/classify/service")
public class ShopClassifyService {

	@Inject
	private JdbcSession jdbcSession;
	@Inject
	private CommunityService communityService;

	@ReqMapping("/list")
	public Object list(JSONObject jsonObject) {
		return jdbcSession.findArray(ShopClassify.class)
				.in(jsonObject, "id")
				.eq(jsonObject,  "communityNo")
				.like(jsonObject, "name","employeeNos")
				.eq("deleted", false)
				.exe();
	}

    @ReqMapping("/get")
    public Object get(ShopClassify item) {
    	return item;
    }
    
    @Bean(newInstance=true, copy=true)
    @ReqMapping("/save")
    public Object save(ShopClassify shopClassify) {
    	if (!communityService.isCommunityExist(shopClassify.getCommunityNo())) {
    		return Result.error(0, "小区不存在");
    	}

    	jdbcSession.insert(shopClassify);
    	return Result.success(shopClassify);
    }

    @Bean(copy=true)
    @ReqMapping("/update")
    public Object update(ShopClassify shopClassify) throws Exception {
    	if (!communityService.isCommunityExist(shopClassify.getCommunityNo())) {
    		return Result.error(0, "小区不存在");
    	}

    	jdbcSession.updateById(shopClassify);
    	return Result.success();
    }

    @ReqMapping("/delete")
	public Object delete(ShopClassify item) {
		item.setDeleted(true);
		jdbcSession.updateById(item);

		return Result.success();
	}

}
